package com.car.rental.order.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import lombok.Data;

@Configuration
@ConfigurationProperties(prefix = "alipay")
@Data
public class AlipayConfig {
    private Boolean sandbox;
    private String appId;
    private String merchantPrivateKey;
    private String alipayPublicKey;
    private String notifyUrl;
    private String returnUrl;
    private String gatewayUrl;
    private Integer timeout;
    private Integer connectTimeout;

    @Bean
    public AlipayClient alipayClient() {
        DefaultAlipayClient client = new DefaultAlipayClient(
            gatewayUrl,
            appId,
            merchantPrivateKey,
            "json",
            "UTF-8",
            alipayPublicKey,
            "RSA2"
        );
        client.setConnectTimeout(connectTimeout);
        client.setReadTimeout(timeout);
        return client;
    }
}